package com.muse.app.controller;

import com.muse.app.service.CustomerArchivesService;
import com.muse.app.service.UserService;
import com.muse.entity.CustomerOperation;
import com.muse.entity.Result;
import com.muse.interceptor.CurrentContext;
import com.muse.model.CreateCustomerArchivesParam;
import com.muse.model.CustomerArchivesVo;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.index.qual.PolyUpperBound;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/muse/customerArchives")
@Slf4j
public class CustomerArchivesController {
    @Autowired
    private CustomerArchivesService customerArchivesService;

    /**
     * 添加客户档案
     *
     * @param param
     * @return
     */
    @PostMapping("/create")
    public Result createCustomerArchives(@RequestBody CreateCustomerArchivesParam param) {
        log.info("app CustomerArchives create,param={}", param);
        return customerArchivesService.createCustomerArchives(param, CurrentContext.getUserId());
    }

    @PostMapping("/list")
    public Result<List<CustomerArchivesVo>> list(@RequestParam(name = "page", defaultValue = "1") Integer page,
                                                 @RequestParam(name = "pageSize", defaultValue = "30") Integer pageSize) {
        log.info("app CustomerArchives list,userId={}", CurrentContext.getUserId());
        return customerArchivesService.list(CurrentContext.getUserId(), page, pageSize);
    }


    /**
     * 添加操作记录
     *
     * @param param
     * @return
     */
    @PostMapping("/createOperation")
    public Result createCustomerOperation(@RequestBody CreateCustomerArchivesParam param) {
        log.info("app CustomerArchives createCustomerOperation,param={}", param);
        return customerArchivesService.createCustomerOperation(param);
    }

    /**
     * 添加操作记录
     *
     * @param param
     * @return
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") Integer id) {
        log.info("app CustomerArchives delete,id={}", id);
        return customerArchivesService.delete(id);
    }


    @GetMapping("/operation/list/{id}")
    public Result<List<CustomerOperation>> operationList(@PathVariable("id") Integer id,
                                                         @RequestParam(name = "page", defaultValue = "1") Integer page,
                                                         @RequestParam(name = "pageSize", defaultValue = "30") Integer pageSize) {
        log.info("app CustomerArchives operationList,id={}", id);
        return customerArchivesService.operationList(id, page, pageSize);
    }

}
